package com.hbean.controller;

import com.hbean.entity.SysUser;
import com.hbean.service.LoginService;
import com.hbean.system.annotation.LogMethod;
import com.hbean.system.config.Base;
import com.hbean.utils.HUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description: null
 * @Project: hbean
 * @Author: hjibo
 * @CreateDate: 2018-09-30 10:36
 * @ModificationHistory:
 */

@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController extends Base{

    @Autowired
    private LoginService loginService;

    @RequestMapping("/loginIn")
    @LogMethod(logName = "loginIn",logType = 1)
    public Map loginIn(HttpServletRequest request){

        SysUser sysUser = null;
        try {
            String subInfo = request.getParameter("subInfo");
            String loginName = HUtil.jsonStrToKeyValue(subInfo,"name");
            String password = HUtil.jsonStrToKeyValue(subInfo,"password");
            sysUser = loginService.loginIn(loginName,password);

            if(sysUser != null) return mapResult(SUCCESS_CODE,SUCCESS_MSG,LONG_0L,sysUser);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return mapResult(ERROR_CODE,ERROR_MSG,LONG_0L,null);
    }

    @RequestMapping("/loginOff")
    @LogMethod(logName = "loginOff",logType = 1)
    public Map loginOff(){
        return mapResult(SUCCESS_CODE,SUCCESS_MSG,LONG_0L,null);
    }

}
